﻿namespace KeRui.Upload
{
    using System;
    using System.Collections.Specialized;
    using System.Reflection;

    public class UploadedFileCollection : NameObjectCollectionBase
    {
        internal UploadedFileCollection()
        {
        }

        internal void AddFile(string field, UploadedFile file)
        {
            base.BaseAdd(field, file);
        }

        public UploadedFile Get(int index)
        {
            UploadedFile file;
            try
            {
                file = (UploadedFile) base.BaseGet(index);
            }
            catch (Exception exception)
            {
                if (Settings.Current.Advanced.LogExceptions)
                {
                    Log.ExceptionDetails(exception);
                }
                throw exception;
            }
            return file;
        }

        public UploadedFile Get(string key)
        {
            UploadedFile file;
            try
            {
                file = (UploadedFile) base.BaseGet(key);
            }
            catch (Exception exception)
            {
                if (Settings.Current.Advanced.LogExceptions)
                {
                    Log.ExceptionDetails(exception);
                }
                throw exception;
            }
            return file;
        }

        public string GetKey(int index)
        {
            string str;
            try
            {
                str = base.BaseGetKey(index);
            }
            catch (Exception exception)
            {
                if (Settings.Current.Advanced.LogExceptions)
                {
                    Log.ExceptionDetails(exception);
                }
                throw exception;
            }
            return str;
        }

        public string[] AllKeys
        {
            get
            {
                string[] strArray;
                try
                {
                    strArray = base.BaseGetAllKeys();
                }
                catch (Exception exception)
                {
                    if (Settings.Current.Advanced.LogExceptions)
                    {
                        Log.ExceptionDetails(exception);
                    }
                    throw exception;
                }
                return strArray;
            }
        }

        public UploadedFile this[string key]
        {
            get
            {
                UploadedFile file;
                try
                {
                    file = (UploadedFile) base.BaseGet(key);
                }
                catch (Exception exception)
                {
                    if (Settings.Current.Advanced.LogExceptions)
                    {
                        Log.ExceptionDetails(exception);
                    }
                    throw exception;
                }
                return file;
            }
        }

        public UploadedFile this[int index]
        {
            get
            {
                UploadedFile file;
                try
                {
                    file = (UploadedFile) base.BaseGet(index);
                }
                catch (Exception exception)
                {
                    if (Settings.Current.Advanced.LogExceptions)
                    {
                        Log.ExceptionDetails(exception);
                    }
                    throw exception;
                }
                return file;
            }
        }
    }
}

